# Maintainer: Christopher Degawa <ccom@randomderp.com>

_realname=dav1d
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.7.1
pkgrel=1
pkgdesc="AV1 cross-platform decoder focused on speed and correctness (mingw-w64)"
arch=('any')
url='https://code.videolan.org/videolan/dav1d'
license=('BSD')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-nasm"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('staticlibs' 'strip' 'emptydirs')
source=("https://downloads.videolan.org/pub/videolan/dav1d/${pkgver}/dav1d-${pkgver}.tar.xz"{,.asc})
sha256sums=('3334b5d05ec00b0745f94e2c57e23f1874197c4b435a6656cc65af531e73d3c2'
            'SKIP')
validpgpkeys=('65F7C6B4206BD057A7EB73787180713BE58D1ADC') # VideoLAN Release Signing Key

build() {
  cd "${srcdir}"
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

  ${MINGW_PREFIX}/bin/meson \
      --default-library both \
      --buildtype plain \
      -Denable_tests=false \
      ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/ninja
}

check() {
  cd build-${MINGW_CHOST}
  ${MINGW_PREFIX}/bin/meson test
}

package() {
  DESTDIR=${pkgdir}${MINGW_PREFIX} ninja -C "${srcdir}/build-${MINGW_CHOST}" install

  for pcfile in "${pkgdir}${MINGW_PREFIX}"/lib/pkgconfig/*.pc; do
    sed -i "s|$(cygpath -m ${MINGW_PREFIX})|${MINGW_PREFIX}|g" "${pcfile}"
  done

  # License
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/doc/PATENTS" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/PATENTS"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/README.md" "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/README.md"
}
